package cn.kennylee.codehub.mq.lip.integration.rocketmq;

import cn.kennylee.codehub.mq.lip.integration.IntegrationMqConfig;
import cn.kennylee.codehub.mq.lip.integration.rocketmq.listener.AbstractRocketMqListener;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * <p> RocketMQ集成配置 </p>
 * <p>Created on 2025/4/16.</p>
 *
 * @author kennylee
 * @since 0.0.1
 */
@AutoConfiguration
@ConditionalOnClass({RocketMQTemplate.class, AbstractRocketMqListener.class})
@AutoConfigureAfter({RocketMQAutoConfiguration.class, IntegrationMqConfig.class})
@ConditionalOnProperty(prefix = "app.mq.integration.rocketmq", name = "enable", havingValue = "true", matchIfMissing = true)
@Slf4j
public class IntegrationRocketMqConfig {

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "app.mq.integration.consumer", name = "enable", havingValue = "true", matchIfMissing = true)
    public RocketMqListenerRegistrar rocketMqListenerRegistrar() {
        return new RocketMqListenerRegistrar();
    }

    @PostConstruct
    public void init() {
        log.debug("RocketMQ集成配置，已加载");
    }
}
